<template>
  <div>
    <el-table
      :data="dataList"
      border
      stripe
      v-loading="dataListLoading"
      style="width: 100%; margin-top: 20px;">
      <el-table-column prop="userNum" header-align="center" align="center" label="登入用户名"></el-table-column>
      <el-table-column prop="userName" header-align="center" align="center" label="姓名"></el-table-column>
      <el-table-column prop="userPhone" header-align="center" align="center" label="电话"></el-table-column>
      <el-table-column prop="userEmail" header-align="center" align="center" label="邮箱"></el-table-column>
      <el-table-column prop="userPost" header-align="center" align="center" label="职务"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="250" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="lookHandle(scope.row.userNum)">查看权限</el-button>
          <el-button type="text" size="small" @click="resetSecret(scope.row.userNum)">重置密码</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
      style="margin-top: 20px;"
    >
    </el-pagination>
  </div>
</template>

<script>
import research from '@/api/research'
import user from '../../api/user'
import myUtils from '../../api/myUtils'
export default {
  data() {
    return {
      dataList: [
        {
          id:0,
        },
      ],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false

    }
  },
  created() {
    this.isadmin()

  },
  methods: {


    isadmin()
    {
      let role =myUtils.getRole(this.$route.query.subjectPkId,this.$store.getters.roles,this.$store.getters.isSystemAdministrator);
      if(role!=8)
      {
        this.$message.error("您不是系统管理员");
      }
      else {
        this.getDataList();
      }
    },


    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },

    getDataList()
    {
      this.dataListLoading = true;
      this.dataListLoading = false;
      user.userSearch(this.pageIndex,this.pageSize).then(response=>{
        this.dataList = response.data.records;
        this.totalPage = response.data.total;

      });


      // research.getByResearchByUser(this.$store.getters.name,this.pageIndex,this.pageSize).then(response=>{
      //   this.dataList = response.data.records;
      //   this.totalPage = response.data.total;
      //
      // });
      //@发现一个问题在then里面的datalist和在外面的datalist不一样 有可能是更新完列表就消失了
    },
    lookHandle(userNum)
    {
     // this.$store.commit('set_subjectPkId',subjectPkId)

      this.$router.push({path:`/upload/userInfo?userNum=${userNum}`})
    },
    resetSecret(UserNum)
    {
      user.resetPassWord(UserNum).then(({ code }) => {
        if (code  === '000000') {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 700,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        } else {
          this.$message.error(data.msg);
        }
      });




    }



  },

}
</script>
<style>


</style>
